package com.jerry.walking.module.activityPage.adapter;

import android.content.Context;
import android.graphics.Bitmap;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;

import com.jerry.walking.base.BasePageAdapter;
import com.jerry.walking.module.activityPage.bean.ActivityContent;
import com.jerry.walking.utils.BitmapUtils;

import java.util.List;

/**
 * Created by Administrator on 2016/5/13 0013.
 */
public class ImagePagerAdapter extends BasePageAdapter{

    private Context context;
    private List list;
    private ActivityContent activityContent;

    public ImagePagerAdapter(Context context, List list, ActivityContent activityContent){
        this.list = list;
        this.context = context;
        this.activityContent = activityContent;
    }

    @Override
    public int getCount(){
        return list.size();
    }

    @Override
    public boolean isViewFromObject(View view, Object object){
        return view == object;
    }

    @Override
    public Object instantiateItem(ViewGroup container, int position){
        ImageView imageView =null;
        ViewGroup.LayoutParams params = new ViewGroup.LayoutParams(40, 40);
        for(int i = 0; i < activityContent.getPictures().size(); i++){
            imageView  = new ImageView(context);

            String picture = activityContent.getPictures().get(i).getPicture();
            Bitmap bitmap = BitmapUtils.getHttpBitmap(picture);
            imageView.setLayoutParams(params);
            //显示
            imageView.setImageBitmap(bitmap);
            if(i%5 == 0){
                ((ViewGroup) list.get(position)).addView(imageView);
            }

        }

        container.addView((ViewGroup) list.get(position));
        return list.get(position);
    }


    @Override
    public void destroyItem(ViewGroup container, int position, Object object){
        //            super.destroyItem(container, position, object);
//        ((ViewGroup)list.get(position)).removeAllViews();
        container.removeView((ViewGroup) list.get(position));
    }
}
